// pages/affiche/affiche.js
let app = getApp();
Page({
  data: {       
      typeValue:[],    
      tab:1,
      year:0,  
      type:0,  //开工库
      showTab:0
  }, 

  //招商库统计操作
  yearChange:function(e){
      this.setData({year:e.detail.value});
      this.publicApi();
  },
  //查看整体情况
  yearClear:function(){
    this.setData({year:0});
    this.publicApi();
  },

  //开工库操作
  typeClick:function(e){
    this.setData({type:e.currentTarget.dataset.id});
    this.publicApi();
  },

  //双千库操作
  showTabClick:function(e){
    this.setData({showTab:e.currentTarget.dataset.val});
  },

  publicApi:function(){
    var tab = parseInt(this.data.tab);
    var url = "";
    switch(tab){
      case 1:
         url = '/api/Statistics/zhaoshang';
        break;
      case 2:
        url = '/api/Statistics/yubei';
        break;
      case 3:
        url = '/api/Statistics/kaigong';
        break;
        case 4:
          url = '/api/Statistics/zhongdian';
          break;
      case 5:
        url = '/api/Statistics/rutong';
        break;
      case 6:
        url = '/api/Statistics/shuangqian';
        break;
    }
    
    if(url!=""){
      var year = this.data.year;
      var type = this.data.type;
      var params = {year:year,type:type};
      var that = this;
      app.request('post', url, params).then(res => {
          var data = res.data;
          if(data.code==0){
            that.setData(data);
          }
      }).catch(err => console.log(err));
    }
  },



  //错误提示
  errorShow:function(title){
    wx.showToast({
      title: title,
      icon: 'none',
      duration: 1500,
    });
  },

  selTab:function(e){
    var tab = e.currentTarget.dataset.id;
    this.setData({tab:tab,year:0,type:0});
    this.publicApi();
  },

  async init(){

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.publicApi();
  },

  onLoad: function () {
 
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})